package com.lilihub.miaosha.util;


import org.apache.commons.codec.digest.DigestUtils;

/**
 * @BelongsProject: miaosha2
 * @BelongsPackage: com.lilihub.miaosha.util
 * @Author: LiYing
 * @CreateTime: 2021-04-24 16:02
 * @Description:
 */
public class MD5Util {


    private static final String salt = "1a2b3c4d";



    /**
     * 对明文字符串做MD5加密
     */
    public static String md5(String str){

        return DigestUtils.md5Hex(str);
    }



    /**
     * 一次MD5加密:明文 + 固定Salt
     */
    public static String inputPassFormPass(String inputPass){

        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);

        return md5(str);
    }

    /**
     * 两次MD5加密: 用户输入 + 随机Salt
     */
    public static String formPassfToDBPass(String formPass,String salt){

        String str = "" + salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(4);

        return md5(str);
    }

    /**
     * 用户输入的密码转化为在数据库中存储的密码
     */
    public static String inputPassfToDBPass(String input,String saltDB){

        String formPass = inputPassFormPass(input);
        String str = formPassfToDBPass(formPass, saltDB);

        return md5(str);
    }


    public static void main(String[] args) {

//        System.out.println(inputPassFormPass("89"));
//        System.out.println(formPassfToDBPass(inputPassFormPass("89"),"abcdefg"));

        System.out.println(inputPassfToDBPass("2345","4534vert"));

    }

}
